package com.ytd.common.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatTextView;

import com.ytd.common.R;

public class TitleTextView extends AppCompatTextView {
    int startColor, endColor;

    public TitleTextView(Context context) {
        this(context, null);
    }

    public TitleTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TitleTextView(Context context, AttributeSet attrs,
                         int defStyle) {
        super(context, attrs, defStyle);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleTextView);
        startColor = typedArray.getColor(R.styleable.TitleTextView_gradient_startColor, 0);
        endColor = typedArray.getColor(R.styleable.TitleTextView_gradient_endColor, 0);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        LinearGradient linearGradient =
            new LinearGradient(0, 0, 0, getHeight(), startColor, endColor, Shader.TileMode.CLAMP);
        getPaint().setShader(linearGradient);
        super.onDraw(canvas);

    }

}
